jQuery().ready(
			function(){
				initdialog();
				initJQGrid();
			});

function initJQGrid(){
	jQuery("#list1").jqGrid({
							url : '/apps/list',
							datatype : "json",
							mtype: 'POST',
							colModel : [ 
								{name:'id',hidden:true,key:true,width:30 },    
								{label:'系统名称',name:'name',index:'name',width:30,editable:false },     
								{label:'监控类型',name:'type',index:'taskName', width:100,editable:false},     
								{label:'监控频率(分钟)',name:'frequency', width:100,editable:false},       
								{label:'描述',name:'desc', width:100,editable:false},
								{label:'当前状态',name:'status',index:'status', width:100,editable:false},   
								{label:'操作',name:'', width:100,editable:false,formatter:optsButton}
							],
							rowNum : 10,
							height: 'auto',
							autowidth : true,
							rowList : [ 10, 20, 30 ],
							pager : '#pager1',
							sortname : 'name',
							viewrecords : true,
							sortorder : "name",
							multiselect: true,
							jsonReader: { repeatitems : false, id: "0" ,root: "items"},
							cellEdit: false,
							caption : "应用系统监控",
							loadComplete: function() {
	                        
	                        
		                        $(".ui-jqgrid tr.ui-row-ltr td img.remove").on("click",function(obj){
		                        	var id=$(obj.target).attr('rowid')
		                        	if(id){
		                        		$("#list1").delGridRow(id,{url:'delete?id='+id,caption:'确认',msg:'删除所选记录吗?',bSubmit:'确认',bCancel:'取消',reloadAfterSubmit:true});
		                        	}
		                        	return false;
		                        });
	                        
	                        	 $(".ui-jqgrid tr.ui-row-ltr td img.edit").on("click",function(obj){
		                        	var id=$(obj.target).attr('rowid')
		                        	if(id){
										window.location.href="info?id="+id;
		                        	}
		                        	return false;
		                        });
	                       
							}
						})
						
						jQuery("#list1").navGrid('#pager1',{edit:false,add:false,del:false,search:false}).navButtonAdd('#pager1'
							,{  
								caption:"", buttonicon:"ui-icon-search",   
								onClickButton: function(){searchevent();}, position:"last"  
						    }
						).navButtonAdd('#pager1',
							{
								caption:"", buttonicon:"ui-icon-plus",   
								onClickButton: function(){
										window.location.href="info";
								},
								position:"last"  
						    });	
						    
				function optsButton(cellValue,operations,rowObject){ 			
				 		return '<img class="pause" rowid='+rowObject['id']+' src="../../themes/default/images/icons/pause.png"/>'+
				 				'<img class="edit" rowid='+rowObject['id']+' src="../../themes/default/images/icons/edit.png"/>'+
				 				'<img class="remove" rowid='+rowObject['id']+' src="../../themes/default/images/icons/remove.png"/>';
				 }    

}


function initdialog (){
	$( ".searchbar" ).dialog({
autoOpen: false,
height: 250,
width: 400,
modal: true,
buttons: {
"查询": function() {
queryDevice();
},
"取消": function() {
$( this ).dialog( "close" );
}
},
close: function() {

}
});
}
var  searchevent = function(){
	$( ".searchbar" ).dialog( "open" );
}

